import time

from appium.webdriver.common.appiumby import By
from selenium.webdriver.support.wait import WebDriverWait

from appPage.enter_homepage import EnterHomePage
from config import PHONE, PWD
from utils.driver_utils import DriverUtils


class Login:
    def login(self, driver, phone, password):
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID, value="com.tpshop.malls:id/mine_img")).click()
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID, value="com.tpshop.malls:id/head_img")).click()
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID, value="com.tpshop.malls:id/mobile_et")).send_keys(phone)
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID, value="com.tpshop.malls:id/pwd_et")).send_keys(password)
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID, value="com.tpshop.malls:id/agree_btn")).click()
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID, value="com.tpshop.malls:id/login_tv")).click()

if __name__ == '__main__':
    driver_utils = DriverUtils()
    driver = driver_utils.get_driver()
    enter = EnterHomePage()
    login = Login()
    enter.enter_homepage(driver)
    login.login(driver, PHONE, PWD)
    time.sleep(5)
    driver_utils.quit_driver()